//这个是所有前端请求的入口
package com.lxc.main;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import javax.servlet.annotation.MultipartConfig;
//mapping 
import com.lxc.mapping.Admin;
import com.lxc.common.PathManagement;
import com.lxc.mapping.AddMusic;
import com.lxc.mapping.GetMusic;

@MultipartConfig
public class MusicManagementSystem implements Servlet{
	public void init(ServletConfig config) throws ServletException{}
	public void service(ServletRequest request,ServletResponse response) throws ServletException,IOException{
		//获取请求方式
		HttpServletRequest httpRequest = (HttpServletRequest)request;
		String httpMethod = httpRequest.getMethod();
		//System.out.println(httpMethod);//测试1
		if(httpMethod.equals("GET")){
			doGet((HttpServletRequest)request,(HttpServletResponse)response);
		}
		else if(httpMethod.equals("POST")){
			doPost((HttpServletRequest)request,(HttpServletResponse)response);
		}
		else{}
	}
	public ServletConfig getServletConfig(){ return null;}
	public String getServletInfo(){return null;}
	public void destroy(){};
	
	//自定义方法
	private void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException{
		//HttpServletRequest 获取url的各种方法测试
		//System.out.println("getContextPath:"+request.getContextPath());
		//System.out.println("getPathInfo："+request.getPathInfo());
		//System.out.println("getQueryString:"+request.getQueryString());
		//System.out.println("getRequestURI:"+request.getRequestURI());
		//System.out.println("getRequestURL:"+request.getRequestURL());
		System.out.println("getServletPath:"+request.getServletPath());
		String servletPath = request.getServletPath();
		if(servletPath.equals("/")){
			Admin admin = new Admin(request,response);
			admin.responseAdminPage();
			
		}
		else if(servletPath.equals("/user/getmusic")){
			GetMusic getMusic = new GetMusic(request,response);
			getMusic.getMusic();
		}
		System.out.println("doGet");//测试2
		
	}
	private void doPost(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException{
		System.out.println("doPost");
		String servletPath = request.getServletPath();
		if(servletPath.equals("/admin/addmusic")){
			AddMusic addMusic = new AddMusic(request,response);
			addMusic.addMusic();
		}
	}
}